﻿$(document).ready(function () {
    $("#cancel").click(function () {
        window.top.tb_remove();
    });
    $.fn.serializeObject = function () {
        var obj = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (obj[this.name]) {
                if (!obj[this.name].push) {
                    obj[this.name] = [obj[this.name]];
                }
                obj[this.name].push(this.value || '');
            } else {
                obj[this.name] = this.value || '';
            }
        });
        return obj;
    };
    var mainForm = $("#submit1").parent().parent();

    var i = 1;
    $("#submit1").click(function () {
        if (i == 0) {
            alert("正在处理提交数据!");
            return false;
        }
     
        if (publicchecked.validted&&publicchecked.validted()) {
            $(this).text("提交中...");
            i = 0;
            //var data = $("#mainForm").serialize();
           var  dataq=$("#mainForm").serializeObject();
            $.ajax({
                url:location.href,
                data: dataq,
                type: "POST",
                success: function (data) {
                    i = 1;
                    if (data&&data.code == 0) {
                        alert("失败：" + data.Message);
                        $("#submit1").text("提交");
                        return false;
                    }
                    alert("操作成功!");                   
                    window.parent.location.href = parent.location.href;

                },
                error: function (result) {
                	alert(result);
                    alert("Error");
                }
            });
        }
        //alert("没有验证");
       // window.parent.location.href = parent.location.href;
    });


    var isture = true;
    mainForm.submit(function () {
        if (mainForm.valid()) {
            if (isture) {
                isture = false;
                $("#submitloading").show();
            }
            else {
                $(".validation-summary-errors").hide(8000);
                return false;
            }


        } else {
            $(".validation-summary-errors").hide(8000);
        }
    });

    $(".integer").numeric(false, function () { alert("只能输入数字"); this.value = ""; this.focus(); });
});
